/*
 * Copyright 2019 Zhang XueHai
 * you may not use this file except in compliance with the License.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.zhangxuehai.android.pdfviewer.annotation.pen;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import com.zhangxuehai.android.pdfviewer.PDFView;
import java.util.List;

/**
 * 删除线画笔
 * @author 章学海
 * @date 2019/12/31
 */
class StrikethroughPen implements Pen.MarkPen {
    /**画笔颜色*/
    private int color;
    private transient Paint paint;

    StrikethroughPen(int color) {
        this.color = color;
        init();
    }

    @Override
    public void draw(List<RectF> list, Canvas canvas, float scale, int basePenWidth, PDFView pdfView, int page) {
        if(list==null || list.size() == 0){
            return;
        }
        List<RectF> datas = mergeRect(list,pdfView,page);
        for (RectF f : datas) {
            f.left /=scale;
            f.top /=scale;
            f.right /=scale;
            f.bottom /=scale;
            float y = (f.top + f.bottom) /2;
            canvas.drawLine(f.left,y,f.right,y,paint);
        }
    }

    @Override
    public PenType getPenType() {
        return PenType.STRIKETHROUGH;
    }

    @Override
    public void init() {
        paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(color);
        paint.setStrokeWidth(2);
        paint.setStrokeCap(Paint.Cap.SQUARE);
    }
}
